const express = require("express");
const cors = require("cors"); // 为客户端提供跨域资源请求
const axios = require("axios");
const qs = require("qs");

const app = express();

app.use(express.json());
app.use(
  express.urlencoded({
    extended: true,
  })
);
app.use(cors());

const server = axios.create();

let cookie = ''

app.use("/attendances", async (req, res) => {
  const { data } = await server.post(
    "https://www.yunzhijia.com/attendance/rest/web-record/clockInUsers",
    qs.stringify(req.body),
    {
      headers: {
        "content-type": "application/x-www-form-urlencoded",
        cookie
      },
      params: {
        lappName: "attendance",
      },
    }
  );
  res.status(200).json(data)
});

app.use("/setCookie", async (req, res) => {  
  cookie = req.body.cookie
  res.status(200).end('cookie设置成功')
});

app.listen(3003, () => {
  console.log(`server is running at http://localhost:3003`);
});
